package com.sanyang.pda.ui.manualpallet;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sanyang.pda.adapter.PalletDetailAdapter;
import com.sanyang.pda.bean.PalletDetailBean;
import com.sanyang.pda.contract.PalletDetailContract;
import com.sanyang.pda.presenter.PalletDetailPresenter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpFragment;
import com.wangshen.projectbase.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class PalletDetailFragment extends BaseMvpFragment<PalletDetailPresenter> implements PalletDetailContract.View, OnRefreshListener {
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    PalletDetailAdapter adapter;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    private String entryNo;

    public PalletDetailFragment() {
    }

    public PalletDetailFragment(String entryNo) {
        this.entryNo = entryNo;
    }

    @Override
    public PalletDetailPresenter getPresenter() {
        return new PalletDetailPresenter();
    }

    @Override
    public int getViewId() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView() {
        smart.setEnableRefresh(true);
        smart.setEnableLoadMore(false);
        smart.setOnRefreshListener(this);
        rvList.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new PalletDetailAdapter(R.layout.item_detail_pallet, new ArrayList<>());
        rvList.setAdapter(adapter);
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {
       smart.autoRefresh();
    }

    @Override
    public void setList(List<PalletDetailBean> list) {
        smart.finishRefresh();
        adapter.setNewInstance(list);
    }
    @Override
    public void showMessage(String msg) {
        super.showMessage(msg);
        smart.finishRefresh();
    }
    @Override
    public void onRefresh(RefreshLayout refreshLayout) {
        presenter.palletDetail(entryNo);
    }
}
